<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='文章管理',active='article'">
<header th:replace="admin/header::headerFragment(${title},${active})"></header>

<link th:href="@{/admin/plugins/select2.dist.css/select2-bootstrap.css}" rel="stylesheet"/>
<link th:href="@{/multi-select/0.9.12/css/multi-select.css}" rel="stylesheet"/>
<link th:href="@{/select2/3.4.8/select2.min.css}" rel="stylesheet"/>

<body class="fixed-left">
<div id="wrapper">
    <div th:replace="admin/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-6">
                        <h4 class="page-title">文章管理</h4>
                    </div>

                    <div class="row">
                        <div class="col-md-12" style="padding: 20px;">
                            <div class="panel panel-primary">
                                <div class="panel-body">
                                    <form id="searchForm" class="form-inline" role="form" novalidate="novalidate"
                                          th:action="@{'/admin/article/search'}">

                                        <!--<div class="form-group col-md-3">
                                            <select id="multiple-sel" class="select2 form-control" multiple="multiple"
                                                    data-placeholder="请选择分类...">
                                                <th:block th:unless="${null == categories}">
                                                    <th:block th:each="c : ${categories}">
                                                        <option th:value="${c.name}" th:text="${c.name}"
                                                                th:selected="${null !=contents and adminCommons.exist_cat(c, contents.categories)}?true:false"></option>
                                                    </th:block>
                                                </th:block>
                                            </select>
                                        </div>-->

                                        <div class="form-group">
                                            <select id="multiple-sel" name="category" class="form-control" data-placeholder="请选择分类">
                                                <!--<th:block th:if="${null != category}">
                                                    <option th:value="${category}" th:text="${category}" selected="selected"></option>
                                                </th:block>-->
                                                <th:block th:if="${null != categories}">
                                                    <option value="" >请选择分类...</option>
                                                    <th:block th:each="c : ${categories}">
                                                        <option th:value="${c.name}" th:text="${c.name}"
                                                                th:selected="${c.name==category}?true:false"></option>
                                                    </th:block>
                                                </th:block>
                                            </select>
                                        </div>

                                        <div class="form-group">
                                            <select id="state" name="state" class="form-control" data-placeholder="请选择状态">
                                                <option value="" >请选择状态...</option>
                                                <option value="publish" th:selected="${state=='publish'}?true:false">发布</option>
                                                <option value="draft" th:selected="${state=='draft'}?true:false">草稿</option>
                                                <option value="delete" th:selected="${state=='delete'}?true:false">删除</option>
                                                <option value="personal" th:selected="${state=='personal'}?true:false">隐私</option>
                                            </select>
                                        </div>

                                        <div class="form-group">
                                            <input type="text" id="keyword" name="keyword" class="form-control" style="width:300px"
                                                   placeholder="请输入搜索关键字" th:value="${keyword}"/>
                                        </div>

                                        <button type="submit" class="btn btn-success waves-effect waves-light m-l-10">搜索</button>
                                    </form>


                                </div> <!-- panel-body -->
                            </div> <!-- panel -->
                        </div> <!-- col -->

                    </div>

                    <div class="row ">
                        <div class="col-md-12">
                            <table class="table table-striped table-bordered">
                                <thead>
                                <tr>
                                    <th width="35%">文章标题</th>
                                    <th width="15%">发布时间</th>
                                    <th>浏览量</th>
                                    <th>所属分类</th>
                                    <th width="8%">发布状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <th:block th:each="post : ${articles.list}">
                                    <tr th:cid="${post.cid}">
                                        <td>
                                            <a th:href="@{'/admin/article/'+${post.cid}}" th:text="${post.title}"></a>
                                        </td>
                                        <td><th:block th:text="${commons.fmtdate(post.modified, 'yyyy-MM-dd HH:mm:ss')}"/></td>
                                        <td><th:block th:text="${post.hits}"/></td>
                                        <td><th:block th:text="${post.categories}"/></td>
                                        <td>
                                            <th:block th:if="${post.status == 'publish'}">
                                                <span class="label label-success">已发布</span>
                                            </th:block>
                                           <th:block th:if="${post.status == 'draft'}">
                                               <span class="label label-default">草稿</span>
                                           </th:block>
                                            <th:block th:if="${post.status == 'delete'}">
                                                <span class="label label-danger">删除</span>
                                            </th:block>
                                            <th:block th:if="${post.status == 'personal'}">
                                                <span class="label label-warning">隐私</span>
                                            </th:block>
                                        </td>
                                        <td>
                                            <a th:href="@{'/admin/article/'+${post.cid}}"
                                               class="btn btn-primary btn-sm waves-effect waves-light m-b-5"><i
                                                    class="fa fa-edit"></i> <span>编辑</span></a>
                                            <a href="javascript:void(0)" th:onclick="'delPost('+${post.cid}+');'"
                                               class="btn btn-danger btn-sm waves-effect waves-light m-b-5"><i
                                                    class="fa fa-trash-o"></i> <span>删除</span></a>
                                            <a class="btn btn-warning btn-sm waves-effect waves-light m-b-5" th:href="@{${commons.permalink(post)}+'/preview'}"
                                               target="_blank"><i
                                                    class="fa fa-rocket"></i> <span>预览</span></a>
                                        </td>
                                    </tr>
                                </th:block>

                                </tbody>
                            </table>
                            <div th:replace="comm/macros :: pageAdminNav3(${articles})"></div>
                        </div>
                    </div>
                </div>
                <div th:replace="admin/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="admin/footer :: footer"></div>

<script th:src="@{/admin/plugins/tagsinput/jquery.tagsinput.min.js}"></script>
<script th:src="@{/admin/plugins/jquery-multi-select/jquery.quicksearch.js}"></script>

<script th:src="@{/admin/plugins/md/js/jquery.scrollto.js}"></script>
<script th:src="@{/admin/plugins/md/js/pagedown.js}"></script>
<script th:src="@{/admin/plugins/md/js/pagedown-extra.js}"></script>
<script th:src="@{/admin/plugins/md/js/diff.js}"></script>
<script th:src="@{/admin/plugins/md/js/md.js}"></script>

<!--<script th:src="@{//cdn.bootcss.com/multi-select/0.9.12/js/jquery.multi-select.min.js}"></script>
<script th:src="@{//cdn.bootcss.com/select2/3.4.8/select2.min.js}"></script>
<script th:src="@{//cdn.bootcss.com/jquery-toggles/2.0.4/toggles.min.js}"></script>-->
<script th:src="@{/multi-select/0.9.12/js/jquery.multi-select.min.js}"></script>
<script th:src="@{/select2/3.4.8/select2.min.js}"></script>
<script th:src="@{/jquery-toggles/2.0.4/toggles.min.js}"></script>
<script th:src="@{/admin/js/article.js}"></script>

<script type="text/javascript">
    /*<![CDATA[*/
    var tale = new $.tale();
    function delPost(cid) {
        tale.alertConfirm({
            title:'确定删除该文章吗?',
            then: function () {
                tale.post({
                    url : getContextPath() + '/admin/article/delete',
                    data: {cid: cid},
                    success: function (result) {
                        if(result && result.success){
                            tale.alertOkAndReload('文章删除成功');
                        } else {
                            tale.alertError(result.msg || '文章删除失败');
                        }
                    }
                });
            }
        });
    };

    /*$("#multiple-sel").multipleSelect({
        single: true
    });*/
    /*]]>*/
</script>
</body>
</html>